// Controller for checking last modified time
package com.itheima.vmmysql.Controller;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FileChangeController {

    private static final String SOURCE_FILE_PATH = "html/index.html"; // replace with actual
                                                                                                 // path
    private long lastModified = new File(SOURCE_FILE_PATH).lastModified();

    @GetMapping("/checkFileChange")
    public Map<String, Boolean> checkFileChange() {
        Map<String, Boolean> response = new HashMap<>();
        File file = new File(SOURCE_FILE_PATH);
        long currentLastModified = file.lastModified();
        if (currentLastModified > lastModified) {
            lastModified = currentLastModified;
            response.put("changed", true);
        } else {
            response.put("changed", false);
        }
        return response;
    }
}
